package com.tsd.system.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.tsd.core.jwt.AccessToken;
import com.tsd.core.utils.DateUtil;
import com.tsd.core.utils.HlpUtils;

import java.util.Date;
import java.util.List;

/**
 * 描述：SysUser 模型扩展
 *
 * @author Hillpool
 * @date 2019/03/12 12:20:51
 */
public class SysUserExt extends SysUser {
    /**
     * 表名
     */
    final public static String TABLE_NAME = "sys_user";
    /**
     * 基础模块资源的一级编码
     */
    final public static String PARENT_CODE4ABASE_MODULE = "base";
    //部门名称
    private String group_name;
    //职务名称
    private String duty_name;
    private String role_sid;
    private String role_name;
    private String role_code;
    //当前单位信息
    private SysGroup sysGroup;

    private List<String> resourseList;

    private List<String> clientList;
    //绑定的角色sid列表
    private List<String> role_sid_list;

    private String group_person_sid;

    private String group_person_name;

    private String person_group_sid;
    private String person_group_name;
    /**
     * 是否需要更新sysd_group_person记录
     * 1-是：将原来的更新，
     * 0（null)-否，检查有绑定了其他账户，则报错
     */
    final public static int UPDATE_PERSON_YES = 1;
    final public static int UPDATE_PERSON_NO = 0;
    private Integer update_person = UPDATE_PERSON_NO;

    private List<String> sid_list;

    private List<SysUserResourceExt> userResourceList;

    private List<SysUserClientExt> userClientList;

    private AccessToken accessToken;
    private AccessToken refreshToken;
    /**
     * 与第三方系统的绑定
     */
    private List<SysExtSysUserExt> bindList;

    private String account_set_sid;
    /**
     * 登录后打开的url
     */
    private String url_after_logined;

    private String token_type;

    private String client_sid;

    private String open_id;

    private String device_type;

    private Integer ver;

    @JsonFormat(pattern = "yyyy-MM-dd", locale = "zh", timezone = "GMT+8")
    private Date expired_date;

    public SysUserExt() {
    }

    public SysUserExt(SysRegUserExt userExt) {
        this.setId(userExt.getId());
        this.setSid(userExt.getSid());
        this.setName(userExt.getName());
        this.setLogin_id(userExt.getLogin_id());
        this.setClient_sid(userExt.getClient_sid());
        this.setOpen_id(userExt.getOpen_id());
    }

    public boolean needUpdatePerson() {
        return update_person != null && update_person == UPDATE_PERSON_YES;
    }

    public String getGroup_name() {
        return group_name;
    }

    public void setGroup_name(String group_name) {
        this.group_name = group_name;
    }

    public String getDuty_name() {
        return duty_name;
    }

    public void setDuty_name(String duty_name) {
        this.duty_name = duty_name;
    }

    public SysGroup getSysGroup() {
        return sysGroup;
    }

    public void setSysGroup(SysGroup sysGroup) {
        this.sysGroup = sysGroup;
    }

    public List<String> getResourseList() {
        return resourseList;
    }

    public void setResourseList(List<String> resourseList) {
        this.resourseList = resourseList;
    }

    public List<String> getClientList() {
        return clientList;
    }

    public void setClientList(List<String> clientList) {
        this.clientList = clientList;
    }

    public String getGroup_person_sid() {
        return group_person_sid;
    }

    public void setGroup_person_sid(String group_person_sid) {
        this.group_person_sid = group_person_sid;
    }

    public String getGroup_person_name() {
        return group_person_name;
    }

    public void setGroup_person_name(String group_person_name) {
        this.group_person_name = group_person_name;
    }

    public String getPerson_group_sid() {
        return person_group_sid;
    }

    public void setPerson_group_sid(String person_group_sid) {
        this.person_group_sid = person_group_sid;
    }

    public String getPerson_group_name() {
        return person_group_name;
    }

    public void setPerson_group_name(String person_group_name) {
        this.person_group_name = person_group_name;
    }

    public Integer getUpdate_person() {
        return update_person;
    }

    public void setUpdate_person(Integer update_person) {
        this.update_person = update_person;
    }

    public List<String> getSid_list() {
        return sid_list;
    }

    public void setSid_list(List<String> sid_list) {
        this.sid_list = sid_list;
    }

    public List<SysUserResourceExt> getUserResourceList() {
        return userResourceList;
    }

    public void setUserResourceList(List<SysUserResourceExt> userResourceList) {
        this.userResourceList = userResourceList;
    }

    public List<SysUserClientExt> getUserClientList() {
        return userClientList;
    }

    public void setUserClientList(List<SysUserClientExt> userClientList) {
        this.userClientList = userClientList;
    }

    public AccessToken getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(AccessToken accessToken) {
        this.accessToken = accessToken;
    }

    public AccessToken getRefreshToken() {
        return refreshToken;
    }

    public void setRefreshToken(AccessToken refreshToken) {
        this.refreshToken = refreshToken;
    }

    public List<String> getRole_sid_list() {
        return role_sid_list;
    }

    public void setRole_sid_list(List<String> role_sid_list) {
        this.role_sid_list = role_sid_list;
    }

    public String getRole_sid() {
        return role_sid;
    }

    public void setRole_sid(String role_sid) {
        this.role_sid = role_sid;
    }

    public String getRole_name() {
        return role_name;
    }

    public void setRole_name(String role_name) {
        this.role_name = role_name;
    }

    public String getRole_code() {
        return role_code;
    }

    public void setRole_code(String role_code) {
        this.role_code = role_code;
    }

    public List<SysExtSysUserExt> getBindList() {
        return bindList;
    }

    public void setBindList(List<SysExtSysUserExt> bindList) {
        this.bindList = bindList;
    }

    public String getAccount_set_sid() {
        return account_set_sid;
    }

    public void setAccount_set_sid(String account_set_sid) {
        this.account_set_sid = account_set_sid;
    }

    public String getUrl_after_logined() {
        return url_after_logined;
    }

    public void setUrl_after_logined(String url_after_logined) {
        this.url_after_logined = url_after_logined;
    }

    public String getToken_type() {
        return token_type;
    }

    public void setToken_type(String token_type) {
        this.token_type = token_type;
    }

    public String getClient_sid() {
        return client_sid;
    }

    public void setClient_sid(String client_sid) {
        this.client_sid = client_sid;
    }

    public String getOpen_id() {
        return open_id;
    }

    public void setOpen_id(String open_id) {
        this.open_id = open_id;
    }

    public String getDevice_type() {
        return device_type;
    }

    public void setDevice_type(String device_type) {
        this.device_type = device_type;
    }

    public Integer getVer() {
        return ver;
    }

    public void setVer(Integer ver) {
        this.ver = ver;
    }

    public Date getExpired_date() {
        return expired_date;
    }

    public void setExpired_date(Date expired_date) {
        this.expired_date = expired_date;
    }
    public Integer getExpired_days(){
        if (expired_date == null){
            return null;
        }
        try {
            return DateUtil.dateSub(expired_date, HlpUtils.getTheDate(new Date()));
        }catch (Exception e){
            return null;
        }
    }
    public SysUserExt cloneBase() {
        SysUserExt userExt = new SysUserExt();
        userExt.setId(this.getId());
        userExt.setSid(this.getSid());
        userExt.setName(this.getName());
        userExt.setLogin_id(this.getLogin_id());
        userExt.setClient_sid(this.getClient_sid());
        userExt.setOpen_id(this.getOpen_id());
        userExt.setGroup_sid(this.getGroup_sid());
        userExt.setClient_auth_mode(this.getClient_auth_mode());
        userExt.setClient_auth_setting(this.getClient_auth_setting());
        userExt.setDevice_type(this.getDevice_type());
        return userExt;
    }
}
